package indexbuilder;

import java.util.ArrayList;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;

import common.Activity;

public class ActivityDocument {

	public static Document getDocument(Activity act){
		Document doc = new Document();
		doc.add(new Field(Activity.NAME, act.getName(), Field.Store.YES, Field.Index.ANALYZED));
		doc.add(new Field(Activity.ACTURL, act.getActURL(), Field.Store.YES, Field.Index.NO));
		doc.add(new Field(Activity.IMGURL, act.getImgURL(), Field.Store.YES, Field.Index.NO));
		doc.add(new Field(Activity.BEGINTIME, act.getBeginTime(), Field.Store.YES, Field.Index.NOT_ANALYZED));
		doc.add(new Field(Activity.FINISHTIME, act.getFinishTime(), Field.Store.YES, Field.Index.NOT_ANALYZED));
		doc.add(new Field(Activity.AREA, act.getArea(), Field.Store.YES, Field.Index.ANALYZED));
		doc.add(new Field(Activity.ORGANIZERS, getStringFromArrayList(act.getOrganizers()), Field.Store.YES, Field.Index.ANALYZED));
		doc.add(new Field(Activity.KIND, act.getKind(), Field.Store.YES, Field.Index.ANALYZED));
		doc.add(new Field(Activity.SUMMARY, act.getSummary(), Field.Store.YES, Field.Index.ANALYZED));
		doc.add(new Field(Activity.INTERESTNUM, act.getInterestNum(), Field.Store.YES, Field.Index.NO));
		doc.add(new Field(Activity.JOINNUM, act.getJoinNum(), Field.Store.YES, Field.Index.NO));
		doc.add(new Field(Activity.PHOTONUM, act.getPhotoNum(), Field.Store.YES, Field.Index.NO));
		return doc;
	}
	
	private static String getStringFromArrayList(ArrayList<String> arrayList){
		StringBuilder sbui = new StringBuilder();
		for (String item : arrayList){
			sbui.append(" "+item);
		}
		return sbui.toString().substring(1);
	}
}
